package cn.lingnan.dao;

import com.mongodb.client.result.DeleteResult;
import lingnan.entity.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.stereotype.Component;

import org.springframework.data.mongodb.core.query.Query;
import java.util.List;

@Component
public class OrderDao {
    @Autowired
    private MongoTemplate mongoTemplate;

    public List<Order> findOrders(){
        List<Order> orderBeanList = mongoTemplate.findAll(Order.class);
        return orderBeanList;
    }

    public void deleteById(String orderID){
        Query query=new Query(Criteria.where("orderID").is(orderID));
        System.out.println("orderDao::::::deleteById");
        mongoTemplate.remove(query,Order.class);

    }

    public Order insertOrder(Order order) {
       return mongoTemplate.save(order);
    }


}
